package com.bot.rf.config;

import com.bot.rf.entity.BookLocation;

/**
 * @program: report-form-demo
 * @description: 图书馆基本信息配置类
 * @author: zyy
 * @create: 2021-02-24 14:21
 **/
public class LibraryConfig {

    /**
     * 图书馆全称
     */
    public static String LIBRARY_NAME = "华东师范大学";

    /**
     * 图书馆代码
     */
    public static String LIBRARY_CODE = "ECNU";

    /**
     * 上线：true   测试：false
     */
    public static boolean IS_ONLINE = true;

    /**
     *
     *
     * @param bookLocation
     * @return
     */
    public static String getSheetName(BookLocation bookLocation) {
        int columnNo = bookLocation.getColumnNo();
        int row = bookLocation.getRowNo();
        int tmp = (row + 1) / 2;
        StringBuilder code = new StringBuilder();
        code.append(String.format("%02d", tmp));
        if (row % 2 == 0) {
            code.append("架B面");
        } else {
            code.append("架A面");
        }
        return code.toString();
    }

    /**
     * 盘点层架标
     *
     * @param bookLocation
     * @return
     */
    public static String getBookShelfIndex(BookLocation bookLocation) {
        int shelfNo = bookLocation.getShelfNo();
        int layerNo = bookLocation.getLayerNo();
        StringBuilder shelfNum = new StringBuilder();
        shelfNum.append(String.format("%02d", shelfNo) + "列").append(String.format("%02d", layerNo) + "层");
        return shelfNum.toString();
    }

    /**
     * 盘点层架标代码
     *
     * @param bookLocation
     * @return
     */
    public static String getBookShelfIndexCode(BookLocation bookLocation) {
        // 01040107A11
        int row = bookLocation.getRowNo();
        int tmp = (row + 1) / 2;
        StringBuilder code = new StringBuilder();
        code.append("010401");
        code.append(String.format("%02d", tmp));
        int shelfNo = bookLocation.getShelfNo();
        if (row % 2 == 0) {
            code.append("B");
        } else {
            code.append("A");
        }
        code.append(String.format("%02d", shelfNo));
        return code.toString();
    }

    /**
     *
     * @param shelf
     * @param dataShelf
     * @return
     */
    public static boolean handleErrorShelf(String shelf,String dataShelf){
        // 没开启默认错架
        if (!UserConfig.NEAR_ENABLE){
            return true;
        }
        // 01040107A11
        Integer shelfNo = Integer.valueOf(shelf.substring(9));
        Integer dataShelfNo = Integer.valueOf(dataShelf.substring(9));
        String sPre = shelf.substring(0,9);
        String dPre = dataShelf.substring(0,9);
        if (sPre.equals(dPre)){
            int val = Math.abs(shelfNo - dataShelfNo);
            return (val == 1 || val == 2) ? false : true;
        }else{
            return true;
        }
    }

    public static boolean handleSideError(String shelf,String dataShelf){
        UserConfig userConfig = new UserConfig();
        if (!UserConfig.AB_ENABLE){
            return true;
        }
        String rowNo = shelf.substring(6,8);
        Integer shelfNo = Integer.valueOf(shelf.substring(9));
        Integer dataShelfNo = Integer.valueOf(dataShelf.substring(9));
        // 是否AB对穿，盘点符合A B面
        String s1 = shelf.substring(0,8);
        String s2 = dataShelf.substring(0,8);
        // 0~9不等，0~8等，即9不等

        if (s1.equals(s2)){

            if (!shelf.substring(8,9).equals(dataShelf.substring(8,9))){
                if (rowNo.equals("05") || rowNo.equals("07")){
                    return (shelfNo + dataShelfNo != 16);
                }else{
                    return (shelfNo + dataShelfNo != 13);
                }
            }else{
                return true;
            }

        }else {
            return true;
        }
    }


    public static String handleChangeShelf(String shelfNo,String dataShelfCode){
        String str = dataShelfCode.substring(9);
        return shelfNo.substring(0,5) + str + shelfNo.substring(7);
    }
    public static void main(String[] args) {
        System.out.println(handleSideError("01040105A12","01040105B04"));
    }
}
